
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       battery_monitor_params.c
  * @author     baiyang
  * @date       2022-10-29
  ******************************************************************************
  */

/*----------------------------------include-----------------------------------*/
#include "battery_monitor.h"

#include "battery_monitor_analog.h"

#include <notify/notify.h>
#include <parameter/param.h>
#include <vehicle/vehicle_type.h>
#include <board_config/board_config.h>
/*-----------------------------------macro------------------------------------*/
#if MB_BUILD_COPTER_OR_HELI
  #define DEFAULT_LOW_BATTERY_VOLTAGE 10.5f
#else
  #define DEFAULT_LOW_BATTERY_VOLTAGE 0.0f
#endif // APM_BUILD_COPTER_OR_HELI
/*----------------------------------typedef-----------------------------------*/

/*---------------------------------prototype----------------------------------*/

/*----------------------------------variable----------------------------------*/
static param_t var_info[] = {
    // @Param: MONITOR
    // @DisplayName: Battery monitoring
    // @Description: Controls enabling monitoring of the battery's voltage and current
    // @Values: 0:Disabled,3:Analog Voltage Only,4:Analog Voltage and Current,5:Solo,6:Bebop,7:SMBus-Generic,8:DroneCAN-BatteryInfo,9:ESC,10:Sum Of Selected Monitors,11:FuelFlow,12:FuelLevelPWM,13:SMBUS-SUI3,14:SMBUS-SUI6,15:NeoDesign,16:SMBus-Maxell,17:Generator-Elec,18:Generator-Fuel,19:Rotoye,20:MPPT,21:INA2XX,22:LTC2946,23:Torqeedo,24:FuelLevelAnalog
    // @User: Standard
    // @RebootRequired: True
    PARAM_DEFINE_INT8(BATT_MONITOR, (int8_t)(BATT_MONITOR_NONE)),

    // @Param: CAPACITY
    // @DisplayName: Battery capacity
    // @Description: Capacity of the battery in mAh when full
    // @Units: mAh
    // @Increment: 50
    // @User: Standard
    PARAM_DEFINE_INT32(BATT_CAPACITY, 3300),

    // @Param{Plane}: WATT_MAX
    // @DisplayName: Maximum allowed power (Watts)
    // @Description: If battery wattage (voltage * current) exceeds this value then the system will reduce max throttle (THR_MAX, TKOFF_THR_MAX and THR_MIN for reverse thrust) to satisfy this limit. This helps limit high current to low C rated batteries regardless of battery voltage. The max throttle will slowly grow back to THR_MAX (or TKOFF_THR_MAX ) and THR_MIN if demanding the current max and under the watt max. Use 0 to disable.
    // @Units: W
    // @Increment: 1
    // @User: Advanced
    PARAM_DEFINE_INT16(BATT_WATT_MAX, 0),

    // @Param: SERIAL_NUM
    // @DisplayName: Battery serial number
    // @Description: Battery serial number, automatically filled in for SMBus batteries, otherwise will be -1. With DroneCan it is the battery_id.
    // @User: Advanced
    PARAM_DEFINE_INT32(BATT_SERIAL_NUM, MB_BATT_SERIAL_NUMBER_DEFAULT),

    // @Param: LOW_TIMER
    // @DisplayName: Low voltage timeout
    // @Description: This is the timeout in seconds before a low voltage event will be triggered. For aircraft with low C batteries it may be necessary to raise this in order to cope with low voltage on long takeoffs. A value of zero disables low voltage errors.
    // @Units: s
    // @Increment: 1
    // @Range: 0 120
    // @User: Advanced
    PARAM_DEFINE_INT8(BATT_LOW_TIMER, 10),

    // @Param: FS_VOLTSRC
    // @DisplayName: Failsafe voltage source
    // @Description: Voltage type used for detection of low voltage event
    // @Values: 0:Raw Voltage, 1:Sag Compensated Voltage
    // @User: Advanced
    PARAM_DEFINE_INT8(BATT_FS_VOLTSRC, BattMonitor_LowVoltageSource_Raw),

    // @Param: LOW_VOLT
    // @DisplayName: Low battery voltage
    // @Description: Battery voltage that triggers a low battery failsafe. Set to 0 to disable. If the battery voltage drops below this voltage continuously for more then the period specified by the @PREFIX@LOW_TIMER parameter then the vehicle will perform the failsafe specified by the @PREFIX@FS_LOW_ACT parameter.
    // @Units: V
    // @Increment: 0.1
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT_LOW_VOLT, DEFAULT_LOW_BATTERY_VOLTAGE),

    // @Param: LOW_MAH
    // @DisplayName: Low battery capacity
    // @Description: Battery capacity at which the low battery failsafe is triggered. Set to 0 to disable battery remaining failsafe. If the battery capacity drops below this level the vehicle will perform the failsafe specified by the @PREFIX@FS_LOW_ACT parameter.
    // @Units: mAh
    // @Increment: 50
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT_LOW_MAH, 0.0f),

    // @Param: CRT_VOLT
    // @DisplayName: Critical battery voltage
    // @Description: Battery voltage that triggers a critical battery failsafe. Set to 0 to disable. If the battery voltage drops below this voltage continuously for more then the period specified by the @PREFIX@LOW_TIMER parameter then the vehicle will perform the failsafe specified by the @PREFIX@FS_CRT_ACT parameter.
    // @Units: V
    // @Increment: 0.1
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT_CRT_VOLT, 0.0f),

    // @Param: CRT_MAH
    // @DisplayName: Battery critical capacity
    // @Description: Battery capacity at which the critical battery failsafe is triggered. Set to 0 to disable battery remaining failsafe. If the battery capacity drops below this level the vehicle will perform the failsafe specified by the @PREFIX@_FS_CRT_ACT parameter.
    // @Units: mAh
    // @Increment: 50
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT_CRT_MAH, 0.0f),

    // @Param: FS_LOW_ACT
    // @DisplayName: Low battery failsafe action
    // @Description: What action the vehicle should perform if it hits a low battery failsafe
    // @Values{Plane}: 0:None,1:RTL,2:Land,3:Terminate,4:QLand,6:Loiter to QLand
    // @Values{Copter}: 0:None,1:Land,2:RTL,3:SmartRTL or RTL,4:SmartRTL or Land,5:Terminate,6:Auto DO_LAND_START or RTL
    // @Values{Sub}: 0:None,2:Disarm,3:Enter surface mode
    // @Values{Rover}: 0:None,1:RTL,2:Hold,3:SmartRTL,4:SmartRTL or Hold,5:Terminate
    // @Values{Tracker}: 0:None
    // @Values{Blimp}: 0:None,1:Land
    // @User: Standard
    PARAM_DEFINE_INT8(BATT_FS_LOW_ACT, 0),

    // @Param: FS_CRT_ACT
    // @DisplayName: Critical battery failsafe action
    // @Description: What action the vehicle should perform if it hits a critical battery failsafe
    // @Values{Plane}: 0:None,1:RTL,2:Land,3:Terminate,4:QLand,5:Parachute,6:Loiter to QLand
    // @Values{Copter}: 0:None,1:Land,2:RTL,3:SmartRTL or RTL,4:SmartRTL or Land,5:Terminate,6:Auto DO_LAND_START or RTL
    // @Values{Sub}: 0:None,2:Disarm,3:Enter surface mode
    // @Values{Rover}: 0:None,1:RTL,2:Hold,3:SmartRTL,4:SmartRTL or Hold,5:Terminate
    // @Values{Tracker}: 0:None
    // @Values{Blimp}: 0:None,1:Land
    // @User: Standard
    PARAM_DEFINE_INT8(BATT_FS_CRT_ACT, 0),

    // @Param: ARM_VOLT
    // @DisplayName: Required arming voltage
    // @Description: Battery voltage level which is required to arm the aircraft. Set to 0 to allow arming at any voltage.
    // @Units: V
    // @Increment: 0.1
    // @User: Advanced
    PARAM_DEFINE_FLOAT(BATT_ARM_VOLT, 0.0f),

    // @Param: ARM_MAH
    // @DisplayName: Required arming remaining capacity
    // @Description: Battery capacity remaining which is required to arm the aircraft. Set to 0 to allow arming at any capacity. Note that execept for smart batteries rebooting the vehicle will always reset the remaining capacity estimate, which can lead to this check not providing sufficent protection, it is recommended to always use this in conjunction with the @PREFIX@_ARM_VOLT parameter.
    // @Units: mAh
    // @Increment: 50
    // @User: Advanced
    PARAM_DEFINE_INT32(BATT_ARM_MAH, 0),

    // 20 was BUS

    // @Param: OPTIONS
    // @DisplayName: Battery monitor options
    // @Description: This sets options to change the behaviour of the battery monitor
    // @Bitmask: 0:Ignore DroneCAN SoC, 1:MPPT reports input voltage and current, 2:MPPT Powered off when disarmed, 3:MPPT Powered on when armed, 4:MPPT Powered off at boot, 5:MPPT Powered on at boot, 6:Send resistance compensated voltage to GCS
    // @User: Advanced
    PARAM_DEFINE_INT32(BATT_OPTIONS, 0),

    // @Param: VOLT_PIN
    // @DisplayName: Battery Voltage sensing pin
    // @Description: Sets the analog input pin that should be used for voltage monitoring.
    // @Values: -1:Disabled, 2:Pixhawk/Pixracer/Navio2/Pixhawk2_PM1, 5:Navigator, 13:Pixhawk2_PM2/CubeOrange_PM2, 14:CubeOrange, 16:Durandal, 100:PX4-v1
    // @User: Standard
    // @RebootRequired: True
    PARAM_DEFINE_INT8(BATT_VOLT_PIN, MB_BATT_VOLT_PIN),

    // @Param: CURR_PIN
    // @DisplayName: Battery Current sensing pin
    // @Description: Sets the analog input pin that should be used for current monitoring.
    // @Values: -1:Disabled, 3:Pixhawk/Pixracer/Navio2/Pixhawk2_PM1, 4:CubeOrange_PM2/Navigator, 14:Pixhawk2_PM2, 15:CubeOrange, 17:Durandal, 101:PX4-v1
    // @User: Standard
    // @RebootRequired: True
    PARAM_DEFINE_INT8(BATT_CURR_PIN, MB_BATT_CURR_PIN),

    // @Param: VOLT_MULT
    // @DisplayName: Voltage Multiplier
    // @Description: Used to convert the voltage of the voltage sensing pin (@PREFIX@VOLT_PIN) to the actual battery's voltage (pin_voltage * VOLT_MULT). For the 3DR Power brick with a Pixhawk, this should be set to 10.1. For the Pixhawk with the 3DR 4in1 ESC this should be 12.02. For the PX using the PX4IO power supply this should be set to 1.
    // @User: Advanced
    PARAM_DEFINE_FLOAT(BATT_VOLT_MULT, MB_BATT_VOLTDIVIDER_DEFAULT),

    // @Param: AMP_PERVLT
    // @DisplayName: Amps per volt
    // @Description: Number of amps that a 1V reading on the current sensor corresponds to. With a Pixhawk using the 3DR Power brick this should be set to 17. For the Pixhawk with the 3DR 4in1 ESC this should be 17.
    // @Units: A/V
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT_AMP_PERVLT, MB_BATT_CURR_AMP_PERVOLT_DEFAULT),

    // @Param: AMP_OFFSET
    // @DisplayName: AMP offset
    // @Description: Voltage offset at zero current on current sensor
    // @Units: V
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT_AMP_OFFSET, MB_BATT_CURR_AMP_OFFSET_DEFAULT),

    // @Param: VLT_OFFSET
    // @DisplayName: Volage offset
    // @Description: Voltage offset on voltage pin. This allows for an offset due to a diode. This voltage is subtracted before the scaling is applied
    // @Units: V
    // @User: Advanced
    PARAM_DEFINE_FLOAT(BATT_VLT_OFFSET, 0),

#if MB_BATT_MONITOR_MAX_INSTANCES > 1
    // @Param: MONITOR
    // @DisplayName: Battery monitoring
    // @Description: Controls enabling monitoring of the battery's voltage and current
    // @Values: 0:Disabled,3:Analog Voltage Only,4:Analog Voltage and Current,5:Solo,6:Bebop,7:SMBus-Generic,8:DroneCAN-BatteryInfo,9:ESC,10:Sum Of Selected Monitors,11:FuelFlow,12:FuelLevelPWM,13:SMBUS-SUI3,14:SMBUS-SUI6,15:NeoDesign,16:SMBus-Maxell,17:Generator-Elec,18:Generator-Fuel,19:Rotoye,20:MPPT,21:INA2XX,22:LTC2946,23:Torqeedo,24:FuelLevelAnalog
    // @User: Standard
    // @RebootRequired: True
    PARAM_DEFINE_INT8(BATT2_MONITOR, (int8_t)(BATT_MONITOR_NONE)),

    // @Param: CAPACITY
    // @DisplayName: Battery capacity
    // @Description: Capacity of the battery in mAh when full
    // @Units: mAh
    // @Increment: 50
    // @User: Standard
    PARAM_DEFINE_INT32(BATT2_CAPACITY, 3300),

    // @Param{Plane}: WATT_MAX
    // @DisplayName: Maximum allowed power (Watts)
    // @Description: If battery wattage (voltage * current) exceeds this value then the system will reduce max throttle (THR_MAX, TKOFF_THR_MAX and THR_MIN for reverse thrust) to satisfy this limit. This helps limit high current to low C rated batteries regardless of battery voltage. The max throttle will slowly grow back to THR_MAX (or TKOFF_THR_MAX ) and THR_MIN if demanding the current max and under the watt max. Use 0 to disable.
    // @Units: W
    // @Increment: 1
    // @User: Advanced
    PARAM_DEFINE_INT16(BATT2_WATT_MAX, 0),

    // @Param: SERIAL_NUM
    // @DisplayName: Battery serial number
    // @Description: Battery serial number, automatically filled in for SMBus batteries, otherwise will be -1. With DroneCan it is the battery_id.
    // @User: Advanced
    PARAM_DEFINE_INT32(BATT2_SERIAL_NUM, MB_BATT_SERIAL_NUMBER_DEFAULT),

    // @Param: LOW_TIMER
    // @DisplayName: Low voltage timeout
    // @Description: This is the timeout in seconds before a low voltage event will be triggered. For aircraft with low C batteries it may be necessary to raise this in order to cope with low voltage on long takeoffs. A value of zero disables low voltage errors.
    // @Units: s
    // @Increment: 1
    // @Range: 0 120
    // @User: Advanced
    PARAM_DEFINE_INT8(BATT2_LOW_TIMER, 10),

    // @Param: FS_VOLTSRC
    // @DisplayName: Failsafe voltage source
    // @Description: Voltage type used for detection of low voltage event
    // @Values: 0:Raw Voltage, 1:Sag Compensated Voltage
    // @User: Advanced
    PARAM_DEFINE_INT8(BATT2_FS_VOLTSRC, BattMonitor_LowVoltageSource_Raw),

    // @Param: LOW_VOLT
    // @DisplayName: Low battery voltage
    // @Description: Battery voltage that triggers a low battery failsafe. Set to 0 to disable. If the battery voltage drops below this voltage continuously for more then the period specified by the @PREFIX@LOW_TIMER parameter then the vehicle will perform the failsafe specified by the @PREFIX@FS_LOW_ACT parameter.
    // @Units: V
    // @Increment: 0.1
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT2_LOW_VOLT, DEFAULT_LOW_BATTERY_VOLTAGE),

    // @Param: LOW_MAH
    // @DisplayName: Low battery capacity
    // @Description: Battery capacity at which the low battery failsafe is triggered. Set to 0 to disable battery remaining failsafe. If the battery capacity drops below this level the vehicle will perform the failsafe specified by the @PREFIX@FS_LOW_ACT parameter.
    // @Units: mAh
    // @Increment: 50
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT2_LOW_MAH, 0.0f),

    // @Param: CRT_VOLT
    // @DisplayName: Critical battery voltage
    // @Description: Battery voltage that triggers a critical battery failsafe. Set to 0 to disable. If the battery voltage drops below this voltage continuously for more then the period specified by the @PREFIX@LOW_TIMER parameter then the vehicle will perform the failsafe specified by the @PREFIX@FS_CRT_ACT parameter.
    // @Units: V
    // @Increment: 0.1
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT2_CRT_VOLT, 0.0f),

    // @Param: CRT_MAH
    // @DisplayName: Battery critical capacity
    // @Description: Battery capacity at which the critical battery failsafe is triggered. Set to 0 to disable battery remaining failsafe. If the battery capacity drops below this level the vehicle will perform the failsafe specified by the @PREFIX@_FS_CRT_ACT parameter.
    // @Units: mAh
    // @Increment: 50
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT2_CRT_MAH, 0.0f),

    // @Param: FS_LOW_ACT
    // @DisplayName: Low battery failsafe action
    // @Description: What action the vehicle should perform if it hits a low battery failsafe
    // @Values{Plane}: 0:None,1:RTL,2:Land,3:Terminate,4:QLand,6:Loiter to QLand
    // @Values{Copter}: 0:None,1:Land,2:RTL,3:SmartRTL or RTL,4:SmartRTL or Land,5:Terminate,6:Auto DO_LAND_START or RTL
    // @Values{Sub}: 0:None,2:Disarm,3:Enter surface mode
    // @Values{Rover}: 0:None,1:RTL,2:Hold,3:SmartRTL,4:SmartRTL or Hold,5:Terminate
    // @Values{Tracker}: 0:None
    // @Values{Blimp}: 0:None,1:Land
    // @User: Standard
    PARAM_DEFINE_INT8(BATT2_FS_LOW_ACT, 0),

    // @Param: FS_CRT_ACT
    // @DisplayName: Critical battery failsafe action
    // @Description: What action the vehicle should perform if it hits a critical battery failsafe
    // @Values{Plane}: 0:None,1:RTL,2:Land,3:Terminate,4:QLand,5:Parachute,6:Loiter to QLand
    // @Values{Copter}: 0:None,1:Land,2:RTL,3:SmartRTL or RTL,4:SmartRTL or Land,5:Terminate,6:Auto DO_LAND_START or RTL
    // @Values{Sub}: 0:None,2:Disarm,3:Enter surface mode
    // @Values{Rover}: 0:None,1:RTL,2:Hold,3:SmartRTL,4:SmartRTL or Hold,5:Terminate
    // @Values{Tracker}: 0:None
    // @Values{Blimp}: 0:None,1:Land
    // @User: Standard
    PARAM_DEFINE_INT8(BATT2_FS_CRT_ACT, 0),

    // @Param: ARM_VOLT
    // @DisplayName: Required arming voltage
    // @Description: Battery voltage level which is required to arm the aircraft. Set to 0 to allow arming at any voltage.
    // @Units: V
    // @Increment: 0.1
    // @User: Advanced
    PARAM_DEFINE_FLOAT(BATT2_ARM_VOLT, 0.0f),

    // @Param: ARM_MAH
    // @DisplayName: Required arming remaining capacity
    // @Description: Battery capacity remaining which is required to arm the aircraft. Set to 0 to allow arming at any capacity. Note that execept for smart batteries rebooting the vehicle will always reset the remaining capacity estimate, which can lead to this check not providing sufficent protection, it is recommended to always use this in conjunction with the @PREFIX@_ARM_VOLT parameter.
    // @Units: mAh
    // @Increment: 50
    // @User: Advanced
    PARAM_DEFINE_INT32(BATT2_ARM_MAH, 0),

    // 20 was BUS

    // @Param: OPTIONS
    // @DisplayName: Battery monitor options
    // @Description: This sets options to change the behaviour of the battery monitor
    // @Bitmask: 0:Ignore DroneCAN SoC, 1:MPPT reports input voltage and current, 2:MPPT Powered off when disarmed, 3:MPPT Powered on when armed, 4:MPPT Powered off at boot, 5:MPPT Powered on at boot, 6:Send resistance compensated voltage to GCS
    // @User: Advanced
    PARAM_DEFINE_INT32(BATT2_OPTIONS, 0),

    // @Param: VOLT_PIN
    // @DisplayName: Battery Voltage sensing pin
    // @Description: Sets the analog input pin that should be used for voltage monitoring.
    // @Values: -1:Disabled, 2:Pixhawk/Pixracer/Navio2/Pixhawk2_PM1, 5:Navigator, 13:Pixhawk2_PM2/CubeOrange_PM2, 14:CubeOrange, 16:Durandal, 100:PX4-v1
    // @User: Standard
    // @RebootRequired: True
    PARAM_DEFINE_INT8(BATT2_VOLT_PIN, MB_BATT_VOLT_PIN),

    // @Param: CURR_PIN
    // @DisplayName: Battery Current sensing pin
    // @Description: Sets the analog input pin that should be used for current monitoring.
    // @Values: -1:Disabled, 3:Pixhawk/Pixracer/Navio2/Pixhawk2_PM1, 4:CubeOrange_PM2/Navigator, 14:Pixhawk2_PM2, 15:CubeOrange, 17:Durandal, 101:PX4-v1
    // @User: Standard
    // @RebootRequired: True
    PARAM_DEFINE_INT8(BATT2_CURR_PIN, MB_BATT_CURR_PIN),

    // @Param: VOLT_MULT
    // @DisplayName: Voltage Multiplier
    // @Description: Used to convert the voltage of the voltage sensing pin (@PREFIX@VOLT_PIN) to the actual battery's voltage (pin_voltage * VOLT_MULT). For the 3DR Power brick with a Pixhawk, this should be set to 10.1. For the Pixhawk with the 3DR 4in1 ESC this should be 12.02. For the PX using the PX4IO power supply this should be set to 1.
    // @User: Advanced
    PARAM_DEFINE_FLOAT(BATT2_VOLT_MULT, MB_BATT_VOLTDIVIDER_DEFAULT),

    // @Param: AMP_PERVLT
    // @DisplayName: Amps per volt
    // @Description: Number of amps that a 1V reading on the current sensor corresponds to. With a Pixhawk using the 3DR Power brick this should be set to 17. For the Pixhawk with the 3DR 4in1 ESC this should be 17.
    // @Units: A/V
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT2_AMP_PERVLT, MB_BATT_CURR_AMP_PERVOLT_DEFAULT),

    // @Param: AMP_OFFSET
    // @DisplayName: AMP offset
    // @Description: Voltage offset at zero current on current sensor
    // @Units: V
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT2_AMP_OFFSET, MB_BATT_CURR_AMP_OFFSET_DEFAULT),

    // @Param: VLT_OFFSET
    // @DisplayName: Volage offset
    // @Description: Voltage offset on voltage pin. This allows for an offset due to a diode. This voltage is subtracted before the scaling is applied
    // @Units: V
    // @User: Advanced
    PARAM_DEFINE_FLOAT(BATT2_VLT_OFFSET, 0),
#endif

#if MB_BATT_MONITOR_MAX_INSTANCES > 2
    // @Param: MONITOR
    // @DisplayName: Battery monitoring
    // @Description: Controls enabling monitoring of the battery's voltage and current
    // @Values: 0:Disabled,3:Analog Voltage Only,4:Analog Voltage and Current,5:Solo,6:Bebop,7:SMBus-Generic,8:DroneCAN-BatteryInfo,9:ESC,10:Sum Of Selected Monitors,11:FuelFlow,12:FuelLevelPWM,13:SMBUS-SUI3,14:SMBUS-SUI6,15:NeoDesign,16:SMBus-Maxell,17:Generator-Elec,18:Generator-Fuel,19:Rotoye,20:MPPT,21:INA2XX,22:LTC2946,23:Torqeedo,24:FuelLevelAnalog
    // @User: Standard
    // @RebootRequired: True
    PARAM_DEFINE_INT8(BATT3_MONITOR, (int8_t)(BATT_MONITOR_NONE)),

    // @Param: CAPACITY
    // @DisplayName: Battery capacity
    // @Description: Capacity of the battery in mAh when full
    // @Units: mAh
    // @Increment: 50
    // @User: Standard
    PARAM_DEFINE_INT32(BATT3_CAPACITY, 3300),

    // @Param{Plane}: WATT_MAX
    // @DisplayName: Maximum allowed power (Watts)
    // @Description: If battery wattage (voltage * current) exceeds this value then the system will reduce max throttle (THR_MAX, TKOFF_THR_MAX and THR_MIN for reverse thrust) to satisfy this limit. This helps limit high current to low C rated batteries regardless of battery voltage. The max throttle will slowly grow back to THR_MAX (or TKOFF_THR_MAX ) and THR_MIN if demanding the current max and under the watt max. Use 0 to disable.
    // @Units: W
    // @Increment: 1
    // @User: Advanced
    PARAM_DEFINE_INT16(BATT3_WATT_MAX, 0),

    // @Param: SERIAL_NUM
    // @DisplayName: Battery serial number
    // @Description: Battery serial number, automatically filled in for SMBus batteries, otherwise will be -1. With DroneCan it is the battery_id.
    // @User: Advanced
    PARAM_DEFINE_INT32(BATT3_SERIAL_NUM, MB_BATT_SERIAL_NUMBER_DEFAULT),

    // @Param: LOW_TIMER
    // @DisplayName: Low voltage timeout
    // @Description: This is the timeout in seconds before a low voltage event will be triggered. For aircraft with low C batteries it may be necessary to raise this in order to cope with low voltage on long takeoffs. A value of zero disables low voltage errors.
    // @Units: s
    // @Increment: 1
    // @Range: 0 120
    // @User: Advanced
    PARAM_DEFINE_INT8(BATT3_LOW_TIMER, 10),

    // @Param: FS_VOLTSRC
    // @DisplayName: Failsafe voltage source
    // @Description: Voltage type used for detection of low voltage event
    // @Values: 0:Raw Voltage, 1:Sag Compensated Voltage
    // @User: Advanced
    PARAM_DEFINE_INT8(BATT3_FS_VOLTSRC, BattMonitor_LowVoltageSource_Raw),

    // @Param: LOW_VOLT
    // @DisplayName: Low battery voltage
    // @Description: Battery voltage that triggers a low battery failsafe. Set to 0 to disable. If the battery voltage drops below this voltage continuously for more then the period specified by the @PREFIX@LOW_TIMER parameter then the vehicle will perform the failsafe specified by the @PREFIX@FS_LOW_ACT parameter.
    // @Units: V
    // @Increment: 0.1
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT3_LOW_VOLT, DEFAULT_LOW_BATTERY_VOLTAGE),

    // @Param: LOW_MAH
    // @DisplayName: Low battery capacity
    // @Description: Battery capacity at which the low battery failsafe is triggered. Set to 0 to disable battery remaining failsafe. If the battery capacity drops below this level the vehicle will perform the failsafe specified by the @PREFIX@FS_LOW_ACT parameter.
    // @Units: mAh
    // @Increment: 50
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT3_LOW_MAH, 0.0f),

    // @Param: CRT_VOLT
    // @DisplayName: Critical battery voltage
    // @Description: Battery voltage that triggers a critical battery failsafe. Set to 0 to disable. If the battery voltage drops below this voltage continuously for more then the period specified by the @PREFIX@LOW_TIMER parameter then the vehicle will perform the failsafe specified by the @PREFIX@FS_CRT_ACT parameter.
    // @Units: V
    // @Increment: 0.1
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT3_CRT_VOLT, 0.0f),

    // @Param: CRT_MAH
    // @DisplayName: Battery critical capacity
    // @Description: Battery capacity at which the critical battery failsafe is triggered. Set to 0 to disable battery remaining failsafe. If the battery capacity drops below this level the vehicle will perform the failsafe specified by the @PREFIX@_FS_CRT_ACT parameter.
    // @Units: mAh
    // @Increment: 50
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT3_CRT_MAH, 0.0f),

    // @Param: FS_LOW_ACT
    // @DisplayName: Low battery failsafe action
    // @Description: What action the vehicle should perform if it hits a low battery failsafe
    // @Values{Plane}: 0:None,1:RTL,2:Land,3:Terminate,4:QLand,6:Loiter to QLand
    // @Values{Copter}: 0:None,1:Land,2:RTL,3:SmartRTL or RTL,4:SmartRTL or Land,5:Terminate,6:Auto DO_LAND_START or RTL
    // @Values{Sub}: 0:None,2:Disarm,3:Enter surface mode
    // @Values{Rover}: 0:None,1:RTL,2:Hold,3:SmartRTL,4:SmartRTL or Hold,5:Terminate
    // @Values{Tracker}: 0:None
    // @Values{Blimp}: 0:None,1:Land
    // @User: Standard
    PARAM_DEFINE_INT8(BATT3_FS_LOW_ACT, 0),

    // @Param: FS_CRT_ACT
    // @DisplayName: Critical battery failsafe action
    // @Description: What action the vehicle should perform if it hits a critical battery failsafe
    // @Values{Plane}: 0:None,1:RTL,2:Land,3:Terminate,4:QLand,5:Parachute,6:Loiter to QLand
    // @Values{Copter}: 0:None,1:Land,2:RTL,3:SmartRTL or RTL,4:SmartRTL or Land,5:Terminate,6:Auto DO_LAND_START or RTL
    // @Values{Sub}: 0:None,2:Disarm,3:Enter surface mode
    // @Values{Rover}: 0:None,1:RTL,2:Hold,3:SmartRTL,4:SmartRTL or Hold,5:Terminate
    // @Values{Tracker}: 0:None
    // @Values{Blimp}: 0:None,1:Land
    // @User: Standard
    PARAM_DEFINE_INT8(BATT3_FS_CRT_ACT, 0),

    // @Param: ARM_VOLT
    // @DisplayName: Required arming voltage
    // @Description: Battery voltage level which is required to arm the aircraft. Set to 0 to allow arming at any voltage.
    // @Units: V
    // @Increment: 0.1
    // @User: Advanced
    PARAM_DEFINE_FLOAT(BATT3_ARM_VOLT, 0.0f),

    // @Param: ARM_MAH
    // @DisplayName: Required arming remaining capacity
    // @Description: Battery capacity remaining which is required to arm the aircraft. Set to 0 to allow arming at any capacity. Note that execept for smart batteries rebooting the vehicle will always reset the remaining capacity estimate, which can lead to this check not providing sufficent protection, it is recommended to always use this in conjunction with the @PREFIX@_ARM_VOLT parameter.
    // @Units: mAh
    // @Increment: 50
    // @User: Advanced
    PARAM_DEFINE_INT32(BATT3_ARM_MAH, 0),

    // 20 was BUS

    // @Param: OPTIONS
    // @DisplayName: Battery monitor options
    // @Description: This sets options to change the behaviour of the battery monitor
    // @Bitmask: 0:Ignore DroneCAN SoC, 1:MPPT reports input voltage and current, 2:MPPT Powered off when disarmed, 3:MPPT Powered on when armed, 4:MPPT Powered off at boot, 5:MPPT Powered on at boot, 6:Send resistance compensated voltage to GCS
    // @User: Advanced
    PARAM_DEFINE_INT32(BATT3_OPTIONS, 0),

    // @Param: VOLT_PIN
    // @DisplayName: Battery Voltage sensing pin
    // @Description: Sets the analog input pin that should be used for voltage monitoring.
    // @Values: -1:Disabled, 2:Pixhawk/Pixracer/Navio2/Pixhawk2_PM1, 5:Navigator, 13:Pixhawk2_PM2/CubeOrange_PM2, 14:CubeOrange, 16:Durandal, 100:PX4-v1
    // @User: Standard
    // @RebootRequired: True
    PARAM_DEFINE_INT8(BATT3_VOLT_PIN, MB_BATT_VOLT_PIN),

    // @Param: CURR_PIN
    // @DisplayName: Battery Current sensing pin
    // @Description: Sets the analog input pin that should be used for current monitoring.
    // @Values: -1:Disabled, 3:Pixhawk/Pixracer/Navio2/Pixhawk2_PM1, 4:CubeOrange_PM2/Navigator, 14:Pixhawk2_PM2, 15:CubeOrange, 17:Durandal, 101:PX4-v1
    // @User: Standard
    // @RebootRequired: True
    PARAM_DEFINE_INT8(BATT3_CURR_PIN, MB_BATT_CURR_PIN),

    // @Param: VOLT_MULT
    // @DisplayName: Voltage Multiplier
    // @Description: Used to convert the voltage of the voltage sensing pin (@PREFIX@VOLT_PIN) to the actual battery's voltage (pin_voltage * VOLT_MULT). For the 3DR Power brick with a Pixhawk, this should be set to 10.1. For the Pixhawk with the 3DR 4in1 ESC this should be 12.02. For the PX using the PX4IO power supply this should be set to 1.
    // @User: Advanced
    PARAM_DEFINE_FLOAT(BATT3_VOLT_MULT, MB_BATT_VOLTDIVIDER_DEFAULT),

    // @Param: AMP_PERVLT
    // @DisplayName: Amps per volt
    // @Description: Number of amps that a 1V reading on the current sensor corresponds to. With a Pixhawk using the 3DR Power brick this should be set to 17. For the Pixhawk with the 3DR 4in1 ESC this should be 17.
    // @Units: A/V
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT3_AMP_PERVLT, MB_BATT_CURR_AMP_PERVOLT_DEFAULT),

    // @Param: AMP_OFFSET
    // @DisplayName: AMP offset
    // @Description: Voltage offset at zero current on current sensor
    // @Units: V
    // @User: Standard
    PARAM_DEFINE_FLOAT(BATT3_AMP_OFFSET, MB_BATT_CURR_AMP_OFFSET_DEFAULT),

    // @Param: VLT_OFFSET
    // @DisplayName: Volage offset
    // @Description: Voltage offset on voltage pin. This allows for an offset due to a diode. This voltage is subtracted before the scaling is applied
    // @Units: V
    // @User: Advanced
    PARAM_DEFINE_FLOAT(BATT3_VLT_OFFSET, 0),
#endif

};
PARAM_GROUP_DEFINE(BATT, var_info);
/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
void battery_monitor_assign_param()
{
    battery_monitor_t batt_monitor = battmonitor_get_singleton();

    param_link_variable(PARAM_ID(BATT, BATT_MONITOR), &batt_monitor->_params[0]._type);
    param_link_variable(PARAM_ID(BATT, BATT_CAPACITY), &batt_monitor->_params[0]._pack_capacity);
    param_link_variable(PARAM_ID(BATT, BATT_WATT_MAX), &batt_monitor->_params[0]._watt_max);
    param_link_variable(PARAM_ID(BATT, BATT_SERIAL_NUM), &batt_monitor->_params[0]._serial_number);
    param_link_variable(PARAM_ID(BATT, BATT_LOW_TIMER), &batt_monitor->_params[0]._low_voltage_timeout);
    param_link_variable(PARAM_ID(BATT, BATT_FS_VOLTSRC), &batt_monitor->_params[0]._failsafe_voltage_source);
    param_link_variable(PARAM_ID(BATT, BATT_LOW_VOLT), &batt_monitor->_params[0]._low_voltage);
    param_link_variable(PARAM_ID(BATT, BATT_LOW_MAH), &batt_monitor->_params[0]._low_capacity);
    param_link_variable(PARAM_ID(BATT, BATT_CRT_VOLT), &batt_monitor->_params[0]._critical_voltage);
    param_link_variable(PARAM_ID(BATT, BATT_CRT_MAH), &batt_monitor->_params[0]._critical_capacity);
    param_link_variable(PARAM_ID(BATT, BATT_FS_LOW_ACT), &batt_monitor->_params[0]._failsafe_low_action);
    param_link_variable(PARAM_ID(BATT, BATT_FS_CRT_ACT), &batt_monitor->_params[0]._failsafe_critical_action);
    param_link_variable(PARAM_ID(BATT, BATT_ARM_VOLT), &batt_monitor->_params[0]._arming_minimum_voltage);
    param_link_variable(PARAM_ID(BATT, BATT_ARM_MAH), &batt_monitor->_params[0]._arming_minimum_capacity);
    param_link_variable(PARAM_ID(BATT, BATT_OPTIONS), &batt_monitor->_params[0]._options);
    param_link_variable(PARAM_ID(BATT, BATT_VOLT_PIN), &batt_monitor->_params[0]._volt_pin);
    param_link_variable(PARAM_ID(BATT, BATT_CURR_PIN), &batt_monitor->_params[0]._curr_pin);
    param_link_variable(PARAM_ID(BATT, BATT_VOLT_MULT), &batt_monitor->_params[0]._volt_multiplier);
    param_link_variable(PARAM_ID(BATT, BATT_AMP_PERVLT), &batt_monitor->_params[0]._curr_amp_per_volt);
    param_link_variable(PARAM_ID(BATT, BATT_AMP_OFFSET), &batt_monitor->_params[0]._curr_amp_offset);
    param_link_variable(PARAM_ID(BATT, BATT_VLT_OFFSET), &batt_monitor->_params[0]._volt_offset);

#if MB_BATT_MONITOR_MAX_INSTANCES > 1
    param_link_variable(PARAM_ID(BATT, BATT2_MONITOR), &batt_monitor->_params[1]._type);
    param_link_variable(PARAM_ID(BATT, BATT2_CAPACITY), &batt_monitor->_params[1]._pack_capacity);
    param_link_variable(PARAM_ID(BATT, BATT2_WATT_MAX), &batt_monitor->_params[1]._watt_max);
    param_link_variable(PARAM_ID(BATT, BATT2_SERIAL_NUM), &batt_monitor->_params[1]._serial_number);
    param_link_variable(PARAM_ID(BATT, BATT2_LOW_TIMER), &batt_monitor->_params[1]._low_voltage_timeout);
    param_link_variable(PARAM_ID(BATT, BATT2_FS_VOLTSRC), &batt_monitor->_params[1]._failsafe_voltage_source);
    param_link_variable(PARAM_ID(BATT, BATT2_LOW_VOLT), &batt_monitor->_params[1]._low_voltage);
    param_link_variable(PARAM_ID(BATT, BATT2_LOW_MAH), &batt_monitor->_params[1]._low_capacity);
    param_link_variable(PARAM_ID(BATT, BATT2_CRT_VOLT), &batt_monitor->_params[1]._critical_voltage);
    param_link_variable(PARAM_ID(BATT, BATT2_CRT_MAH), &batt_monitor->_params[1]._critical_capacity);
    param_link_variable(PARAM_ID(BATT, BATT2_FS_LOW_ACT), &batt_monitor->_params[1]._failsafe_low_action);
    param_link_variable(PARAM_ID(BATT, BATT2_FS_CRT_ACT), &batt_monitor->_params[1]._failsafe_critical_action);
    param_link_variable(PARAM_ID(BATT, BATT2_ARM_VOLT), &batt_monitor->_params[1]._arming_minimum_voltage);
    param_link_variable(PARAM_ID(BATT, BATT2_ARM_MAH), &batt_monitor->_params[1]._arming_minimum_capacity);
    param_link_variable(PARAM_ID(BATT, BATT2_OPTIONS), &batt_monitor->_params[1]._options);
    param_link_variable(PARAM_ID(BATT, BATT2_VOLT_PIN), &batt_monitor->_params[1]._volt_pin);
    param_link_variable(PARAM_ID(BATT, BATT2_CURR_PIN), &batt_monitor->_params[1]._curr_pin);
    param_link_variable(PARAM_ID(BATT, BATT2_VOLT_MULT), &batt_monitor->_params[1]._volt_multiplier);
    param_link_variable(PARAM_ID(BATT, BATT2_AMP_PERVLT), &batt_monitor->_params[1]._curr_amp_per_volt);
    param_link_variable(PARAM_ID(BATT, BATT2_AMP_OFFSET), &batt_monitor->_params[1]._curr_amp_offset);
    param_link_variable(PARAM_ID(BATT, BATT2_VLT_OFFSET), &batt_monitor->_params[1]._volt_offset);
#endif

#if MB_BATT_MONITOR_MAX_INSTANCES > 2
    param_link_variable(PARAM_ID(BATT, BATT3_MONITOR), &batt_monitor->_params[2]._type);
    param_link_variable(PARAM_ID(BATT, BATT3_CAPACITY), &batt_monitor->_params[2]._pack_capacity);
    param_link_variable(PARAM_ID(BATT, BATT3_WATT_MAX), &batt_monitor->_params[2]._watt_max);
    param_link_variable(PARAM_ID(BATT, BATT3_SERIAL_NUM), &batt_monitor->_params[2]._serial_number);
    param_link_variable(PARAM_ID(BATT, BATT3_LOW_TIMER), &batt_monitor->_params[2]._low_voltage_timeout);
    param_link_variable(PARAM_ID(BATT, BATT3_FS_VOLTSRC), &batt_monitor->_params[2]._failsafe_voltage_source);
    param_link_variable(PARAM_ID(BATT, BATT3_LOW_VOLT), &batt_monitor->_params[2]._low_voltage);
    param_link_variable(PARAM_ID(BATT, BATT3_LOW_MAH), &batt_monitor->_params[2]._low_capacity);
    param_link_variable(PARAM_ID(BATT, BATT3_CRT_VOLT), &batt_monitor->_params[2]._critical_voltage);
    param_link_variable(PARAM_ID(BATT, BATT3_CRT_MAH), &batt_monitor->_params[2]._critical_capacity);
    param_link_variable(PARAM_ID(BATT, BATT3_FS_LOW_ACT), &batt_monitor->_params[2]._failsafe_low_action);
    param_link_variable(PARAM_ID(BATT, BATT3_FS_CRT_ACT), &batt_monitor->_params[2]._failsafe_critical_action);
    param_link_variable(PARAM_ID(BATT, BATT3_ARM_VOLT), &batt_monitor->_params[2]._arming_minimum_voltage);
    param_link_variable(PARAM_ID(BATT, BATT3_ARM_MAH), &batt_monitor->_params[2]._arming_minimum_capacity);
    param_link_variable(PARAM_ID(BATT, BATT3_OPTIONS), &batt_monitor->_params[2]._options);
    param_link_variable(PARAM_ID(BATT, BATT3_VOLT_PIN), &batt_monitor->_params[2]._volt_pin);
    param_link_variable(PARAM_ID(BATT, BATT3_CURR_PIN), &batt_monitor->_params[2]._curr_pin);
    param_link_variable(PARAM_ID(BATT, BATT3_VOLT_MULT), &batt_monitor->_params[2]._volt_multiplier);
    param_link_variable(PARAM_ID(BATT, BATT3_AMP_PERVLT), &batt_monitor->_params[2]._curr_amp_per_volt);
    param_link_variable(PARAM_ID(BATT, BATT3_AMP_OFFSET), &batt_monitor->_params[2]._curr_amp_offset);
    param_link_variable(PARAM_ID(BATT, BATT3_VLT_OFFSET), &batt_monitor->_params[2]._volt_offset);
#endif
}
/*------------------------------------test------------------------------------*/


